#使用jartools分层构建Docker镜像  提高CI/CD效率
#第一阶段  拆分多个镜像 构建标记为builder
FROM openjdk:11 as builder
MAINTAINER stalk
RUN mkdir -p /opt/{stalk-authority,conf}
WORKDIR /opt/stalk-authority
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
RUN java -Djarmode=layertools -jar app.jar extract

#第二阶段从分层提取并构建镜像
FROM openjdk:11
MAINTAINER stalk
WORKDIR /opt/stalk-authority
#构建底层dependencies  依赖项一般变化不大
COPY --from=builder /opt/stalk-authority/dependencies/ ./
#构建加载器spring-boot-loader  加载器一般变化也不大
COPY --from=builder /opt/stalk-authority/spring-boot-loader/ ./
#构建快照依赖 更迭可能会快点
COPY --from=builder /opt/stalk-authority/snapshot-dependencies/ ./
#构建业务层    频繁变动
COPY --from=builder /opt/stalk-authority/application/ ./
#环境变量默认为dev
ENV ACTIVE=test

ENV sport=18088

ENV LANG C.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL C.UTF-8

RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN echo 'Asia/Shanghai' > /etc/timezone

EXPOSE ${sport}

ENTRYPOINT ["java","org.springframework.boot.loader.JarLauncher","--spring.profiles.active=${ACTIVE}","--server.port=${sport}","-Dfile.encoding=UTF-8"]
